// -----------------------------------------------------------------------
//  <copyright file="CaptchaControlller.cs" company="LiuliuSoft">
//      Copyright (c) 2022-2024 DaprPlus. All rights reserved.
//  </copyright>
//  <site>https://dapr.plus</site>
//  <last-editor>郭明锋</last-editor>
//  <last-date>2024/12/7 18:44:59</last-date>
// -----------------------------------------------------------------------

namespace Liuliu.Fsb.Services.Identity.Api.Controllers
{
    public class CaptchaController : ApiControllerBase
    {
        [HttpGet("{id}")]
        public ActionResult Get(string id)
        {
            var captchaService = HttpContext.RequestServices.GetRequiredService<ICaptchaService>();
            var captcha = captchaService.Generate(id);

            var ms = new MemoryStream(captcha.bytes);
            var result = File(ms, "image/gif");
            return result;
        }

        [HttpGet("{id}/{code}")]
        public ActionResult Validate(string id, string code)
        {
            var captchaService = HttpContext.RequestServices.GetRequiredService<ICaptchaService>();
            var result = captchaService.Validate(id, code, false, false);
            return Ok(result);
        }
    }
}
